package com.nf.health.app.customview;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.utils.ImageUtils;
import com.nf.health.app.utils.ViewUtil;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * 出诊时间绘制
 * 小星星
 * @author yyh
 */
public class MyDisucssView extends LinearLayout implements View.OnClickListener {
    private Context context;
    //上午的星星
    public ImageView iv_mor_star01;
    public ImageView iv_mor_star02;
    public ImageView iv_mor_star03;
    public ImageView iv_mor_star04;
    public ImageView iv_mor_star05;
    public ImageView iv_mor_star06;
    public ImageView iv_mor_star07;

    //下午的星星
    public ImageView iv_afn_star01;
    public ImageView iv_afn_star02;
    public ImageView iv_afn_star03;
    public ImageView iv_afn_star04;
    public ImageView iv_afn_star05;
    public ImageView iv_afn_star06;
    public ImageView iv_afn_star07;


  //  public LinearLayout ll_shoutip;//图片和布局的ll
    public TextView doctor_hospital_doc;//医院的名称
    public TextView tv_way_dcotail_interrogat;//出诊
    public ImageView iv_star_dcotail_small;//展示title的小心星星
 //   public ImageView iv_up_to_down;//展示想上或者是向下的箭头
 //   public LinearLayout ll_iv_up_to_down;//展示想上或者是向下的箭头
    public LinearLayout ll_show_star;//展示上下的小星星
    private LinkedList<ImageView> dayIv = new LinkedList<>();
    private LinkedList<ImageView> morningIv = new LinkedList<>();
    private LinkedList<ImageView> afterIv = new LinkedList<>();

    public MyDisucssView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }
    public MyDisucssView(Context context,int index) {
        super(context);
        initView(context,index);
    }

    /**
     * index 默认第几个展开
     * @param context
     * @param index
     */
    private void initView(Context context,int index) {
        this.context = context;
        // TODO Auto-generated constructor stub
        LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_interrogation, this);

        iv_mor_star01 = ViewUtil.getView(this,R.id.iv_mor_star01);
        iv_mor_star02 = ViewUtil.getView(this,R.id.iv_mor_star02);
        iv_mor_star03 = ViewUtil.getView(this,R.id.iv_mor_star03);
        iv_mor_star04 = ViewUtil.getView(this,R.id.iv_mor_star04);
        iv_mor_star05 = ViewUtil.getView(this,R.id.iv_mor_star05);
        iv_mor_star06 = ViewUtil.getView(this,R.id.iv_mor_star06);
        iv_mor_star07 = ViewUtil.getView(this,R.id.iv_mor_star07);

        iv_afn_star01 = ViewUtil.getView(this,R.id.iv_afn_star01);
        iv_afn_star02 = ViewUtil.getView(this,R.id.iv_afn_star02);
        iv_afn_star03 = ViewUtil.getView(this,R.id.iv_afn_star03);
        iv_afn_star04 = ViewUtil.getView(this,R.id.iv_afn_star04);
        iv_afn_star05 = ViewUtil.getView(this,R.id.iv_afn_star05);
        iv_afn_star06 = ViewUtil.getView(this,R.id.iv_afn_star06);
        iv_afn_star07 = ViewUtil.getView(this,R.id.iv_afn_star07);


       /* iv_up_to_down = ViewUtil.getView(this,R.id.iv_up_to_down);*/
//        ll_shoutip = ViewUtil.getView(this,R.id.ll_shoutip);
        ll_show_star = ViewUtil.getView(this,R.id.ll_show_star);
//        ll_shoutip = ViewUtil.getView(this,R.id.ll_shoutip);
        doctor_hospital_doc = ViewUtil.getView(this,R.id.doctor_hospital_doc);
        tv_way_dcotail_interrogat = ViewUtil.getView(this,R.id.tv_way_dcotail_interrogat);
       /* ll_iv_up_to_down = ViewUtil.getView(this,R.id.ll_iv_up_to_down);*/

       /* morningIv.add(iv_mor_star01);
        morningIv.add(iv_mor_star02);
        morningIv.add(iv_mor_star03);
        morningIv.add(iv_mor_star04);
        morningIv.add(iv_mor_star05);
        morningIv.add(iv_mor_star06);
        morningIv.add(iv_mor_star07);

        afterIv.add(iv_afn_star01);
        afterIv.add(iv_afn_star02);
        afterIv.add(iv_afn_star03);
        afterIv.add(iv_afn_star04);
        afterIv.add(iv_afn_star05);
        afterIv.add(iv_afn_star06);
        afterIv.add(iv_afn_star07);*/

        dayIv.add(iv_mor_star01);
        dayIv.add(iv_mor_star02);
        dayIv.add(iv_mor_star03);
        dayIv.add(iv_mor_star04);
        dayIv.add(iv_mor_star05);
        dayIv.add(iv_mor_star06);
        dayIv.add(iv_mor_star07);

        dayIv.add(iv_afn_star01);
        dayIv.add(iv_afn_star02);
        dayIv.add(iv_afn_star03);
        dayIv.add(iv_afn_star04);
        dayIv.add(iv_afn_star05);
        dayIv.add(iv_afn_star06);
        dayIv.add(iv_afn_star07);

        Integer tag = (Integer) tv_way_dcotail_interrogat.getTag();
        if(index == 0){
            if(tag == null){
                ViewUtil.setTextImgBackground3(tv_way_dcotail_interrogat, context,0,R.drawable.iv_star_smart, 0, R.drawable.home_docinfo_more_up, 0);
              /*  ImageUtils.setImageViewBg(iv_up_to_down, context, R.drawable.home_docinfo_more_up);*/
                tv_way_dcotail_interrogat.setTag(R.drawable.home_docinfo_more_down);
//                ll_shoutip.setVisibility(View.VISIBLE);
                ll_show_star.setVisibility(View.VISIBLE);
            }
        }else if(index > 0){
            ViewUtil.setTextImgBackground3(tv_way_dcotail_interrogat, context,0,R.drawable.iv_star_smart, 0, R.drawable.home_docinfo_more_down, 0);
           // ImageUtils.setImageViewBg(iv_up_to_down, context, R.drawable.home_docinfo_more_down);
            tv_way_dcotail_interrogat.setTag(R.drawable.home_docinfo_more_down);
//            ll_shoutip.setVisibility(View.INVISIBLE);
            ll_show_star.setVisibility(View.GONE);
        }
        tv_way_dcotail_interrogat.setOnClickListener(this);
//        ll_shoutip.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.tv_way_dcotail_interrogat:
                Integer tag = (Integer) tv_way_dcotail_interrogat.getTag();
                if(tag == null){
                    /*ImageUtils.setImageViewBg(iv_up_to_down, context, R.drawable.home_docinfo_more_up);*/
                    ViewUtil.setTextImgBackground3(tv_way_dcotail_interrogat, context,0,R.drawable.iv_star_smart, 0, R.drawable.home_docinfo_more_up, 0);
                    if(tv_way_dcotail_interrogat.getVisibility() == View.VISIBLE){
                        tv_way_dcotail_interrogat.setTag(R.drawable.home_docinfo_more_up);
                    }else{
                        tv_way_dcotail_interrogat.setTag(R.drawable.home_docinfo_more_down);
                    }
                    tag = (Integer) tv_way_dcotail_interrogat.getTag();
                }
                if(tag == R.drawable.home_docinfo_more_down){
                    ViewUtil.setTextImgBackground3(tv_way_dcotail_interrogat, context,0,R.drawable.iv_star_smart, 0, R.drawable.home_docinfo_more_up, 0);
                    /*ImageUtils.setImageViewBg(iv_up_to_down, context, R.drawable.home_docinfo_more_up);*/
//                    ll_shoutip.setVisibility(View.VISIBLE);
                    ll_show_star.setVisibility(View.VISIBLE);
                    tv_way_dcotail_interrogat.setTag(R.drawable.home_docinfo_more_up);
                }else if(tag == R.drawable.home_docinfo_more_up){
                    ViewUtil.setTextImgBackground3(tv_way_dcotail_interrogat, context,0,R.drawable.iv_star_smart, 0, R.drawable.home_docinfo_more_down, 0);
                    /*ImageUtils.setImageViewBg(iv_up_to_down, context, R.drawable.home_docinfo_more_down);*/
//                    ll_shoutip.setVisibility(View.INVISIBLE);
                    ll_show_star.setVisibility(View.GONE);
                    tv_way_dcotail_interrogat.setTag(R.drawable.home_docinfo_more_down);
                }
                break;
        }
    }

    /**
     * 绘制上午的小星星
     */
    public void  setMorningStar(){
        for (int i = 1; i <morningIv.size()+1 ; i++) {
            ImageView imageView = morningIv.get(i-1);
            if(i == 1 || i == 3 || i == 5){//设置光亮的小星星
                ImageUtils.setImageViewBg(imageView,context,R.drawable.iv_star_middle);
            }else{
                ImageUtils.setImageViewBg(imageView,context,R.color.white);
            }
        }
    }
    /**
     * 绘制下午的小星星
     */
    public void  setAfternoonStar(){
        for (int i = 1; i <afterIv.size()+1 ; i++) {
            ImageView imageView = afterIv.get(i-1);
            if(i == 1 || i == 3 || i == 5){//设置光亮的小星星
                ImageUtils.setImageViewBg(imageView,context,R.drawable.iv_star_middle);
            }else{
                ImageUtils.setImageViewBg(imageView,context,R.color.white);
            }
        }
    }
    /**
     * 绘制下午的小星星
     */
    public void  setStarChecked(){
        for (int i = 1; i <afterIv.size()+1 ; i++) {
            ImageView imageView = afterIv.get(i-1);
            if(i == 1 || i == 3 || i == 5){//设置光亮的小星星
                ImageUtils.setImageViewBg(imageView,context,R.drawable.iv_star_middle);
            }else{
                ImageUtils.setImageViewBg(imageView,context,R.color.white);
            }
        }
    }

    /**
     * 绘制小星星的状态
     */
    public void  setCurrentStarChecked(boolean isCheck,ImageView imageView){
        if(isCheck){//设置光亮的小星星
            ImageUtils.setImageViewBg(imageView,context,R.drawable.iv_star_middle);
        }else{
            ImageUtils.setImageViewBg(imageView,context,R.color.white);
        }
    }
    public void  setCurrentStarChecked(String isCheck,ImageView imageView, HashMap<String,String> hworkTimeMap){
        if(hworkTimeMap.containsKey(isCheck) && hworkTimeMap.get(isCheck).equals("1")){
            String  values = hworkTimeMap.get(isCheck);
            setCurrentStarChecked(true, imageView);
        }else{
            setCurrentStarChecked(false, imageView);
        }
    }

    public void setHospitalName(String hostipalName){
        doctor_hospital_doc.setText(TextUtils.isEmpty(hostipalName) ? "": hostipalName);
    }
    public void setPositionStar( HashMap<String,String> hworkTimeMap){
        setCurrentStarChecked("check1",iv_mor_star01,hworkTimeMap);
        setCurrentStarChecked("check2",iv_mor_star02,hworkTimeMap);
        setCurrentStarChecked("check3",iv_mor_star03,hworkTimeMap);
        setCurrentStarChecked("check4",iv_mor_star04,hworkTimeMap);
        setCurrentStarChecked("check5",iv_mor_star05,hworkTimeMap);
        setCurrentStarChecked("check6",iv_mor_star06,hworkTimeMap);
        setCurrentStarChecked("check7",iv_mor_star07,hworkTimeMap);

        setCurrentStarChecked("check8",iv_afn_star01,hworkTimeMap);
        setCurrentStarChecked("check9",iv_afn_star02,hworkTimeMap);
        setCurrentStarChecked("check10",iv_afn_star03,hworkTimeMap);
        setCurrentStarChecked("check11",iv_afn_star04,hworkTimeMap);
        setCurrentStarChecked("check12",iv_afn_star05,hworkTimeMap);
        setCurrentStarChecked("check13",iv_afn_star06,hworkTimeMap);
        setCurrentStarChecked("check14",iv_afn_star07,hworkTimeMap);
    }
}
